package com.egreen.order.service.api.impl;

import com.egreen.common.serviceapi.order.IOrderCountServiceApi;
import com.egreen.order.utils.OrderCountRedisUtil;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;

/**
 * @author cloudJiang
 * @date 2022/9/21 14:09
 */
@DubboService
public class OrderCountAPI implements IOrderCountServiceApi {
    @Autowired
    OrderCountRedisUtil countUtil;

    @Override
    public ArrayList<Integer> getOrderCountDay(String date) {
        ArrayList<Integer> count = new ArrayList<>();

        //返回总订单，进行中订单，已完成订单
        count.add(countUtil.getOrderCountAll(date));
        count.add(countUtil.getOrderCountDay("running", date));
        count.add(countUtil.getOrderCountDay("over", date));

        return count;
    }

    @Override
    public ArrayList<ArrayList<Integer>> getOrderCountDays(String[] dates) {
        ArrayList<ArrayList<Integer>> counts = new ArrayList<>();

        //遍历日期数组，将每日数据添加到数组
        for (String date : dates) {
            ArrayList<Integer> count = new ArrayList<>();

            //获取总订单，进行中订单，已完成订单
            count.add(countUtil.getOrderCountAll(date));
            count.add(countUtil.getOrderCountDay("running", date));
            count.add(countUtil.getOrderCountDay("over", date));

            counts.add(count);
        }

        return counts;
    }

    @Override
    public Integer getOrderAll() {
        return countUtil.getOrderCountAll();
    }
}
